# pta_frequency
pta_frequency <- ols_main(
	outcome = "pta_frequency",
	treatment = "absenteeism",
	resample_FE = TRUE,
	block_FE = TRUE,
	audience_size = TRUE,
	cluster_SE = TRUE,
	covariates = NULL,
	the_data = subset(el, respondent_category == "Complier"),
	dosage = FALSE,
	dosage_indicator = FALSE)

pta_frequency_pvals <- get_RI_pvals(
	outcome = "pta_frequency",
	treatment = "absenteeism",
	resample_FE = TRUE,
	block_FE = TRUE,
	audience_size = TRUE,
	cluster_SE = TRUE,
	covariates = NULL,
	the_data = subset(el, respondent_category == "Complier"),
	dosage = FALSE,
	dosage_indicator = FALSE,
	assignment_data = treatment_assignment,
	extract_function = coef,
	analysis_function = ols_main,
	sims = sims,
	lwr_upr_two = "upr")

# community_state
community_state <- ols_main(
	outcome = "community_state",
	treatment = "absenteeism",
	resample_FE = TRUE,
	block_FE = TRUE,
	audience_size = TRUE,
	cluster_SE = TRUE,
	covariates = NULL,
	the_data = subset(el, respondent_category == "Complier"),
	dosage = FALSE,
	dosage_indicator = FALSE)

community_state_pvals <- get_RI_pvals(
	outcome = "community_state",
	treatment = "absenteeism",
	resample_FE = TRUE,
	block_FE = TRUE,
	audience_size = TRUE,
	cluster_SE = TRUE,
	covariates = NULL,
	the_data = subset(el, respondent_category == "Complier"),
	dosage = FALSE,
	dosage_indicator = FALSE,
	assignment_data = treatment_assignment,
	extract_function = coef,
	analysis_function = ols_main,
	sims = sims,
	lwr_upr_two = "upr")

# gov_resp
gov_resp <- ols_main(
	outcome = "gov_resp",
	treatment = "absenteeism",
	resample_FE = TRUE,
	block_FE = TRUE,
	audience_size = TRUE,
	cluster_SE = TRUE,
	covariates = NULL,
	the_data = subset(el, respondent_category == "Complier"),
	dosage = FALSE,
	dosage_indicator = FALSE)

gov_resp_pvals <- get_RI_pvals(
	outcome = "gov_resp",
	treatment = "absenteeism",
	resample_FE = TRUE,
	block_FE = TRUE,
	audience_size = TRUE,
	cluster_SE = TRUE,
	covariates = NULL,
	the_data = subset(el, respondent_category == "Complier"),
	dosage = FALSE,
	dosage_indicator = FALSE,
	assignment_data = treatment_assignment,
	extract_function = coef,
	analysis_function = ols_main,
	sims = sims,
	lwr_upr_two = "upr")

#setup
control_means <- with(
	el, 
	c(
		"Control Mean",
		round(mean(pta_frequency[absenteeism == 0 & respondent_category == "Complier"],na.rm = TRUE), 2),
		round(mean(community_state[absenteeism == 0 & respondent_category == "Complier"],na.rm = TRUE), 2),
		round(mean(gov_resp[absenteeism == 0 & respondent_category == "Complier"],na.rm = TRUE), 2)
	)
)

pval_lines <- c(
	"RI $p$-values",
	round(pta_frequency_pvals$ri_pvals["absenteeism"],3),
	round(community_state_pvals$ri_pvals["absenteeism"],3),
	round(gov_resp_pvals$ri_pvals["absenteeism"],3)
)

hypothesis_lines <- c(
	"Hypothesis",
	"upr",
	"upr",
	"upr"
)

#make tables
sink("03_tables/ABS_endline_only.tex")
stargazer(
	... = list(
		pta_frequency$fit,
		community_state$fit,
		gov_resp$fit
	),
	type = "latex",
	p = list(
		pta_frequency$ri_pvals,
		community_state$ri_pvals,
		gov_resp$ri_pvals
	),
	se = list(
		pta_frequency$fit_summary[,"Std. Error"],
		community_state$fit_summary[,"Std. Error"],
		gov_resp$fit_summary[,"Std. Error"]
	),
	keep = "absenteeism",
	omit.stat = c("rsq","f","ser"),
	dep.var.labels = c("PTA frequency","Community fundraiser","Parent's responsibility"),
	dep.var.labels.include = TRUE,
	table.layout = "=cd#-t-as=n",
	no.space = T,
	omit = "block_id",
	add.lines = list(
		control_means,
		pval_lines,
		hypothesis_lines,
		c("Block FE",
			"Yes","Yes","Yes")),
	notes.label = "",
	float = FALSE
	# style = "qje"
)
sink()
